﻿/*
 * KLF Headless Browser
 * Written by Kris Oye <kristianoye@gmail.com>
 * Copyright (C) 2011-2012.  All rights reserved.
 */
namespace KLF.Lib.Browser.DOM.HTML
{
    #region Using Statements

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    #endregion

    public class HTMLTableColElement : HTMLBlockBaseElement
    {
        #region Constructors

        internal HTMLTableColElement(Document owner)
            : base(owner, HTMLConstants.HTML_TAG_TABLECOL)
        {
        }

        #endregion

        #region DOM Level 2 HTML Compliance
        
        /// <summary>
        /// Alignment character for cells in a column. 
        /// 
        /// See the char attribute definition in HTML 4.01.
        /// </summary>
        public string ch
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_CHAR);
            }
            set
            {
                if (String.IsNullOrEmpty(value))
                    removeAttribute(HTMLConstants.HTML_ATT_CHAR);
                else
                    setAttribute(HTMLConstants.HTML_ATT_CHAR, value);
            }
        }

        /// <summary>
        /// Offset of alignment character. 
        /// 
        /// See the charoff attribute definition in HTML 4.01.
        /// </summary>
        public string chOff
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_CHAROFF);
            }
            set
            {
                if (String.IsNullOrEmpty(value))
                    removeAttribute(HTMLConstants.HTML_ATT_CHAROFF);
                else
                    setAttribute(HTMLConstants.HTML_ATT_CHAROFF, value);
            }
        }

        /// <summary>
        /// Indicates the number of columns in a group or affected by a 
        /// grouping. See the span attribute definition in HTML 4.01.
        /// </summary>
        public int span
        {
            get
            {
                return getAttributeAsType<int>(HTMLConstants.HTML_ATT_SPAN, 1);
            }
            set
            {
                setAttributeAsType<int>(HTMLConstants.HTML_ATT_SPAN, value);
            }
        }

        /// <summary>
        /// Vertical alignment of cell data in column. 
        /// 
        /// See the valign attribute definition in HTML 4.01.
        /// </summary>
        public string vAlign
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_VALIGN);
            }
            set
            {
                if (String.IsNullOrEmpty(value))
                    removeAttribute(HTMLConstants.HTML_ATT_VALIGN);
                else
                    setAttribute(HTMLConstants.HTML_ATT_VALIGN, value);
            }
        }


        /// <summary>
        /// Default column width. 
        /// 
        /// See the width attribute definition in HTML 4.01.
        /// </summary>
        public string width
        {
            get
            {
                return getAttribute(HTMLConstants.HTML_ATT_WIDTH);
            }
            set
            {
                if (String.IsNullOrEmpty(value))
                    removeAttribute(HTMLConstants.HTML_ATT_WIDTH);
                else
                    setAttribute(HTMLConstants.HTML_ATT_WIDTH, value);
            }
        }

        #endregion

        #region Custom Attributes

        /// <summary>
        /// Returns the containing table element or null if unattached.
        /// </summary>
        public HTMLTableElement tableElement
        {
            get
            {
                HTMLElement p = this;

                do
                {
                    p = p.Parent as HTMLElement;
                }
                while ((p != null) && !(p is HTMLTableElement));

                return (p != null ? p as HTMLTableElement : null);

            }
        }

        #endregion
    }
}
